<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .current{
            color: crimson;
        }
        .parent{
            width: 200px;
            height: 200px;
            border: 1px solid #666;
            position: relative;
        }
        .parent>div{
            width: 200px;
            height: 200px;
            position: absolute;
        }
        .html{
            background: coral;
            z-index: 100;
        }
        .css{
            background: skyblue;
        }
    </style>
</head>
<body>
    <ul>
        <li class="current">html</li>
        <li>css</li>
    </ul>
    <div class="parent">
        <div class="html">html</div>
        <div class="css">css</div>
    </div>

    <script>
        var lis = document.getElementsByTagName("li")
        var divs = document.querySelectorAll(".parent div")
        for(let i=0;i<lis.length;i++){
            lis[i].index = i;  // 下标值
            lis[i].onclick = function(){
                // 1.给所有的li移除class="current"
                for(let i=0;i<lis.length;i++){
                    lis[i].classList.remove("current")
                }
                // 2.给当前的 添加current类
                this.classList.add("current")

                
                // 3.让所有的div隐藏
                for(let i=0;i<divs.length;i++){
                    divs[i].style.display="none"
                }
                // 4.让对应下标的div显示
                divs[this.index].style.display = "block"
            }
            // console.log(lis[i].index);
        }
    </script>
</body>
</html>